class Solution(object):
    def largestNumber(self, nums):
        """
        :type nums: List[int]
        :rtype: str
        """

        def compare(num1, num2):
            com1 = int(str(num1) + str(num2))
            com2 = int(str(num2) + str(num1))
            if com1 > com2:
                return 1
            elif com1 < com2:
                return -1
            else:
                return 0


        def quicksort(nums):
            if len(nums) <= 1:
                return nums
            pivit = nums[0]
            left = []
            right = []
            mid = [pivit]
            for i in range(1, len(nums)):
                com = compare(nums[i], pivit)
                if com == 1:
                    right.append(nums[i])
                elif com == -1:
                    left.append(nums[i])
                else:
                    mid.append(nums[i])

            left = quicksort(left)
            right = quicksort(right)
            #mid = quicksort(mid)
            return left + mid + right

        nums = quicksort(nums)[::-1]
        res = ''
        for num in nums:
            res += str(num)

        return str(int(res))


